using System;

namespace Dbam.DbFramework
{
	/// <summary>
	/// Attribute for a property of an entity that has mappings to child rows in the database.
	/// </summary>
	[AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
	public class ForeignColumnMappingAttribute
		: Attribute
	{
		/// <summary>
		/// The column of the parent table in the mapping.
		/// </summary>
		private string _parentColumnName;

		/// <summary>
		/// Name of the foreign table that contains the child data.
		/// </summary>
		private string _foreignTableName;

		/// <summary>
		/// Name of the column in the foreign table that relate's to this entity.
		/// </summary>
		private string _foreignColumnName;

		/// <summary>
		/// Type of entity to construct for each child data retrieved.
		/// </summary>
		private Type _foreignEntityType;

		/// <summary>
		/// Flag to indicate whether the child data should be selected when this entity's data
		/// is retreived from the data source.
		/// </summary>
		private bool _autoSelect;

		/// <summary>
		/// Initialize the mapping information.
		/// </summary>
		/// <param name="parentColumnName">The parent column name of the mapping.</param>
		/// <param name="foreignTableName">The table of the child rows.</param>
		/// <param name="foreignColumnName">The child column name in the foreign table to map to.</param>
		/// <param name="foreignEntityType">The type of the foreign entity.</param>
		/// <param name="autoSelect">Flag to indicate whether the child data should be loaded when the parent entity is loaded.</param>
		public ForeignColumnMappingAttribute(string parentColumnName, string foreignTableName, string foreignColumnName, Type foreignEntityType, bool autoSelect)
		{
			_parentColumnName = parentColumnName;
			_foreignTableName = foreignTableName;
			_foreignColumnName = foreignColumnName;
			_foreignEntityType = foreignEntityType;
			_autoSelect = autoSelect;
		}

		/// <summary>
		/// Gets the parent column name of the parent-child mapping.
		/// </summary>
		public string ParentColumnName
		{
			get { return _parentColumnName; }
		}

		/// <summary>
		/// Gets the name of the foreign table in the parent-child mapping.
		/// </summary>
		public string ForeignTableName
		{
			get { return _foreignTableName; }
		}

		/// <summary>
		/// Gets the name of the column in the foreign in the parent-child mapping.
		/// </summary>
		public string ForeignColumnName
		{
			get { return _foreignColumnName; }
		}

		/// <summary>
		/// Gets the type of the foreign entity.
		/// </summary>
		public Type ForeignEntityType
		{
			get { return _foreignEntityType; }
		}

		/// <summary>
		/// Gets the flag indicating whether the child data is loaded when the parent entity is loaded.
		/// </summary>
		public bool AutoSelect
		{
			get { return _autoSelect; }
		}
	}
}